package com.ly.controller;

import com.ly.constant.ResultCodeConstant;
import com.ly.pojo.domain.UserCaseDO;
import com.ly.pojo.dto.CreateGroup;
import com.ly.pojo.dto.DeleteGroup;
import com.ly.pojo.dto.RestResult;
import com.ly.pojo.dto.UpdateGroup;
import com.ly.pojo.dto.UserCaseDTO;
import com.ly.pojo.vo.PageResult;
import com.ly.service.UserCaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import java.lang.Integer;
import java.lang.Object;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import jakarta.servlet.http.HttpServletRequest;

/**
 * 用户案例管理
 *
 */
@Tag(name = "用户案例管理")
@RequestMapping("user-case")
@RestController
public class UserCaseController {

    @Autowired
    private UserCaseService userCaseService;

    /**
     * add
     *
     * @param userCaseDTO 用户案例DTO
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "add")
    @ResponseBody
    public RestResult<Boolean> addUserCase(@RequestBody @Validated(CreateGroup.class) UserCaseDTO userCaseDTO) {
        Boolean result = userCaseService.addUserCase(userCaseDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * update
     *
     * @param userCaseDTO 用户案例DTO
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "update")
    @ResponseBody
    public RestResult<Boolean> updateUserCase(@RequestBody @Validated(UpdateGroup.class) UserCaseDTO userCaseDTO) {
        Boolean result = userCaseService.updateUserCase(userCaseDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * delete
     *
     * @param userCaseDTO 用户案例DTO
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "delete")
    @ResponseBody
    public RestResult<Boolean> deleteUserCase(@RequestBody @Validated(DeleteGroup.class) UserCaseDTO userCaseDTO) {
        Boolean result = userCaseService.deleteUserCase(userCaseDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * list
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @Operation(summary = "list")
    public RestResult<PageResult<UserCaseDO>> listUserCases(@Validated Integer pageIndex, @Validated Integer pageSize) {
        PageResult<UserCaseDO> result = userCaseService.listUserCases(pageIndex, pageSize);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * upload-image
     *
     * @param caseId
     * @param file
     * @param request
     * @return
     */
    @RequestMapping(value = "/upload-image", method = RequestMethod.POST)
    @Operation(summary = "upload-image")
    public RestResult<Boolean> uploadUserCaseImage(@Validated Integer caseId, 
                                                   @Validated MultipartFile file, 
                                                   @Validated HttpServletRequest request) {
        Boolean result = userCaseService.uploadUserCaseImage(caseId, file, request);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
